package controllers;

import connectivity.Dbmanager;
import connectivity.QueryManager;
import java.io.*;
import java.util.LinkedList;
import javax.servlet.*;
import javax.servlet.http.*;
import models.Course;

public class ViewEditableCoursesController extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        Dbmanager dbManager = new Dbmanager();
        dbManager.openConnection();
        QueryManager queryManager = new QueryManager(dbManager);
        HttpSession sessie = request.getSession();

        LinkedList<Course> allcourses = queryManager.getAllCourses();

        if ((Integer) sessie.getAttribute("userLevel") == 2) {
            allcourses = queryManager.getAllTeacherCourses((Integer) sessie.getAttribute("userId"));
        }

        request.setAttribute("coursesUitSessie", allcourses);

        dbManager.closeConnection();

        RequestDispatcher dispatcher = request.getRequestDispatcher("/view_editable_courses.jsp");
        dispatcher.forward(request, response);

    }
}
